source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'
# source 'https://github.com/cocoapods/specs.git'
# source 'https://cdn.cocoapods.org/'

# 私有库B依赖了模块A，同时在主工程里 添加A到 development pod，cocoapods 重复生成相同库的uuid
# pod install 警告信息 [!] [Xcodeproj] Generated duplicate UUIDs
install! 'cocoapods', :deterministic_uuids => false

# 源码测试请屏蔽此选项，否则源码库内部调用出现的警告将不会提示
# inhibit_all_warnings!

# use_frameworks! 要求生成的是 .framework 而不是 .a
use_frameworks! # 使用默认，动态链接
# use_frameworks! :linkage => :dynamic # 使用动态链接
# use_frameworks! :linkage => :static # 使用静态链接

# workspace
workspace "JGSourceBaseDemo"

# platform
platform :ios, 12.0

abstract_target "JGSBase" do

  # pod 'JGSourceBase', :git => 'https://github.com/dengni8023/JGSourceBase.git', :commit => 'd620ee8f5c1e782364804da8b5c541d2de38f55c' #'~> 1.4.0'
  # pod 'JGSourceBase', '~> 1.3.0'
  pod 'JGSourceBase', :path => "./.."
  # subspec 功能测试，仅安装需要测试的 subspec
  # pod 'JGSourceBase', :path => "./..",
  # :subspecs => [
  #   # 'Base',
  #   'Category',
  #   # 'DataStorage',
  #   # 'Device',
  #   # 'Encryption',
  #   # 'HUD',
  #   # 'IntegrityCheck',
  #   # 'Reachability',
  #   # 'SecurityKeyboard',
  # ]
  
  JGSPodsScriptBeforeCompile = <<-CMD

  echo "****** 编译开始前，执行Podfile自定义脚本 ******"
  
  echo "执行自定义脚本修改源码 JGSourceBase.xcconfig"
  chmod +x ${PROJECT_DIR}/../JGSScripts/JGSModifyConfigBeforeCompile.sh # sh执行权限
  ${PROJECT_DIR}/../JGSScripts/JGSModifyConfigBeforeCompile.sh # 执行sh
  
  echo "****** 编译前Podfile自定义脚本执行完成 ******"
  
  CMD

  JGSPodsScriptAfterCompile = <<-CMD

  echo "****** 编译结束后，执行Podfile自定义脚本 ******"
  
  echo "执行应用完整性校验资源文件Hash记录脚本"
  chmod +x ${PROJECT_DIR}/../JGSScripts/JGSDemoIntegrityCheckAfterCompile.sh # sh执行权限
  ${PROJECT_DIR}/../JGSScripts/JGSDemoIntegrityCheckAfterCompile.sh # 执行sh
  
  echo "****** 编译后Podfile自定义脚本执行完成 ******"
  
  CMD

  # JGSourceBaseDemo 测试 Pod 引用 JGSourceBase
  target "JGSourceBaseDemo" do
    
    pod 'IQKeyboardManager', '~> 6.5.18' #  https://github.com/hackiftekhar/IQKeyboardManager.git
    
    #pod 'Masonry', '~> 1.1.0' # 该发布版本 mas_safeAreaLayoutGuide 有bug导致多条约束崩溃
    pod 'Masonry', :git => 'https://github.com/SnapKit/Masonry.git', :commit => '8bd77ea92bbe995e14c454f821200b222e5a8804' # https://github.com/cloudkite/Masonry.git
    
    pod 'SDWebImage', '~> 5.19.1' # https://github.com/SDWebImage/SDWebImage
    
    script_phase :name => "JGSPodsScriptBeforeCompile", :script => JGSPodsScriptBeforeCompile, :execution_position => :before_compile
    script_phase :name => "JGSPodsScriptAfterCompile", :script => JGSPodsScriptAfterCompile, :execution_position => :after_compile
    
    # project
    project "JGSourceBaseDemo.xcodeproj"
  end
  
end

# Hooks: pre_install 在Pods被下载后但是还未安装前对Pods做一些改变
pre_install do |installer|
  puts ""
  puts "##### pre_install start #####"

  # 打印installer信息
  #putsInstanceVariables installer, "installer"

  # target has transitive dependencies that include statically linked  解决pod install失败
  # workaround for https://github.com/CocoaPods/CocoaPods/issues/3289
  # Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_static_framework_transitive_dependencies) {}
  
  puts "##### pre_install end #####"
  puts ""
end

# Hooks: post_install 在生成的Xcode project写入硬盘前做最后的改动
post_install do |installer|
  puts ""
  puts "##### post_install start #####"

  # 打印installer信息
  # putsInstanceVariables installer, "installer"
  
  # BuildIndependentTargetsInParallel 并发构建
  installer.pods_project.root_object.attributes['BuildIndependentTargetsInParallel'] = "YES"
  
  installer.pods_project.build_configurations.each do |config|
    # STRIP
    config.build_settings['DEAD_CODE_STRIPPING'] = "YES"
  end
  
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      # 设置Pods最低版本
      if config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'].to_f < 12.0
        config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = 12.0
      end
      # 编译架构
      config.build_settings['ARCHS'] = "$(ARCHS_STANDARD)"
      # 解决最新Mac系统编模拟器译报错：
      # building for iOS Simulator-x86_64 but attempting to link with file built for iOS Simulator-arm64
      # config.build_settings['ONLY_ACTIVE_ARCH'] = false
      # Code Sign: Xcode 14适配
      config.build_settings['CODE_SIGN_STYLE'] = 'Automatic'
      config.build_settings['CODE_SIGN_IDENTITY'] = ""
      config.build_settings['CODE_SIGN_IDENTITY[sdk=appletvos*]'] = ""
      config.build_settings['CODE_SIGN_IDENTITY[sdk=iphoneos*]'] = ""
      config.build_settings['CODE_SIGN_IDENTITY[sdk=watchos*]'] = ""
      config.build_settings['CODE_SIGNING_REQUIRED'] = "NO"
      config.build_settings['CODE_SIGNING_ALLOWED'] = "NO"
      # STRIP
      # config.build_settings['COPY_PHASE_STRIP'] = "YES"
      # config.build_settings['STRIP_INSTALLED_PRODUCT'] = "YES"
      # config.build_settings['STRIP_STYLE'] = "all"
      # config.build_settings['STRIP_SWIFT_SYMBOLS'] = "YES"
      config.build_settings['DEAD_CODE_STRIPPING'] = "YES"
      # Enable Modules
      # Module 是 编译器用于解决头文件引用导致重复编译等问题的方案
      # 通过开启 Enable Modules 配置开关，可以大幅度的降低编译耗时
      # 默认 NO $(CLANG_MODULES_ENABLE_VERIFIER_TOOL)
      # config.build_settings['ENABLE_MODULE_VERIFIER'] = "YES"
      # config.build_settings['MODULE_VERIFIER_SUPPORTED_LANGUAGES'] = "objective-c objective-c++"
      # config.build_settings['CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER'] = "NO"
    end
  end
  
  puts "##### post_install end #####"
  puts ""
end
